package cn.fantasy.thread;

import java.util.concurrent.CountDownLatch;

/**
 * @author ET
 * @description 使用线程的CountDownLatch(倒计数)方法
 * @date 2023/3/10 15:10
 * @Version V1.0
 */
public class ThreadOrderSix {

    public static void main(String[] args) {
        CountDownLatch countDownLatch1 = new CountDownLatch(1);
        CountDownLatch countDownLatch2 = new CountDownLatch(1);

        final Thread thread1 = new Thread(() -> {
            System.out.println("one");
            countDownLatch1.countDown();
        });

        final Thread thread2 = new Thread(() -> {
            try {
                countDownLatch1.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("two");
            countDownLatch2.countDown();
        });

        final Thread thread3 = new Thread(() -> {
            try {
                countDownLatch2.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("three");
        });

        thread1.start();
        thread2.start();
        thread3.start();

    }
}
